package com.mashibing.api.filter;

/**
 * @ClassName:CheckFilterContext
 * @author:[开发者名称]
 * @Description:[类的功能描述]
 * @Date:2025/9/13/19:53
 * @Version:1.0
 */

import com.mashibing.common.model.StandardSubmit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 *
 */
@Component
@RefreshScope//这个注解的作用是动态更新 filtere 从配置文件读取的内容
public class CheckFilterContext {
    @Autowired
    private Map<String,CheckFilter> checkFiltersMap ;
    @Value("${filters:apikey,ip,sign,template}")
    private String filters;

    public void check(StandardSubmit standardSubmit){
        //1.将获取的filter基于,做切分 得到切分的数组  同过数组遍历map 调用check方法 过滤
        String[] filterArray = filters.split(",");
        for (String filter:filterArray){
            CheckFilter checkFilter = checkFiltersMap.get(filter);
            checkFilter.check(standardSubmit);

        }

    }
}

